cmake_minimum_required(VERSION 3.10)
project(plugin_demo)

set(CMAKE_CXX_STANDARD 17)

find_package(behaviortree_cpp REQUIRED)
# set(behaviortree_cpp_INCLUDE_DIRS "/usr/local/include/behaviortree_cpp")
# set(behaviortree_cpp_LIBRARIES "/usr/local/lib/libbehaviortree_cpp.so")
if(behaviortree_cpp_FOUND)
    message(STATUS "BehaviorTree.CPP found: ${behaviortree_cpp_INCLUDE_DIRS}")
    message(STATUS "BehaviorTree.CPP libraries: ${behaviortree_cpp_LIBRARIES}")
else()
    message(FATAL_ERROR "BehaviorTree.CPP NOT found!")
endif()
# 替换为实际的 BehaviorTree.CPP 安装路径
set(behaviortree_cpp_INCLUDE_DIRS "/usr/local/include/behaviortree_cpp")
set(behaviortree_cpp_LIBRARIES "/usr/local/lib/libbehaviortree_cpp.so")
############ C++插件 Create plugin and executor in folder plugin_example ##########
include_directories(${CMAKE_SOURCE_DIR}/include) #CMAKE_SOURCE_DIR指的是根目录的CMakeLists

# 主程序
add_executable(plugin_demo main.cpp)
target_link_libraries(plugin_demo dl)  # 链接dl库

# 包含插件目录
add_subdirectory(plugins/add_plugin)
add_subdirectory(plugins/multiply_plugin)

# 新建目录,用于输出插件
# file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/add_plugin)
# file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/multiply_plugin)



############ 行为树插件Create plugin and executor in folder plugin_example ##########
# library must be SHARED 动作节点
add_library(test_plugin_action SHARED plugin_example/plugin_action.cpp )
# 编译时添加一个宏定义BT_PLUGIN_EXPORT; you must set the definition BT_PLUGIN_EXPORT
# PRIVATE ：指定宏的作用域，表示该宏仅对 test_plugin_action 及其依赖的源文件可见，不会传递给其他依赖此目标的项目
# BT_PLUGIN_EXPORT ：定义的宏名称，通常用于控制符号的导出行为（如动态库的接口导出）。用于在CPP中配合#ifdef使用
target_compile_definitions(test_plugin_action PRIVATE  BT_PLUGIN_EXPORT )


# 修改目标属性，将目标的PREFIX 属性设置为空字符串，即移除默认的库名前缀lib，remove the "lib" prefix. Name of the file will be test_plugin_action.so
set_target_properties(test_plugin_action PROPERTIES PREFIX "")

# link dependencies as usual
target_link_libraries(test_plugin_action ${behaviortree_cpp_LIBRARIES})

# 将主函数编译成可执行文件
add_executable(test_plugin_executor  plugin_example/plugin_executor.cpp )

add_executable(test_plugin_executor_raw  plugin_example/plugin_executor_raw.cpp )

# 包含头文件目录
# target_include_directories(test_plugin_executor PRIVATE
#   ${behaviortree_cpp_INCLUDE_DIRS}
# )
target_link_libraries(test_plugin_executor ${behaviortree_cpp_LIBRARIES})
# target_link_libraries(test_plugin_executor ${BTCPP_LIBRARY})
# target_link_libraries(test_plugin_executor behaviortree_cpp::behaviortree_cpp)

target_link_libraries(test_plugin_executor_raw ${behaviortree_cpp_LIBRARIES})
